class ResumableTransfer(
    private val context: Context,
    private val transferManager: TransferManager
) {
    private val preferences = context.getSharedPreferences("transfer_state", Context.MODE_PRIVATE)

    fun saveTransferState(fileId: String, position: Long) {
        preferences.edit().putLong(fileId, position).apply()
    }

    fun getLastPosition(fileId: String): Long {
        return preferences.getLong(fileId, 0)
    }

    fun clearTransferState(fileId: String) {
        preferences.edit().remove(fileId).apply()
    }

    suspend fun resumeTransfer(file: File, receiver: String) {
        val fileId = file.name.hashCode().toString()
        val lastPosition = getLastPosition(fileId)
        
        transferManager.startTransfer(
            file = file,
            receiver = receiver,
            startPosition = lastPosition
        )
    }
} 